const fs=require('fs');
const path=require('path');

const fileMap=(function(){
    const line='|__';
    const space='  ';
    let self,config;

    return {
        init: function (opts) {
            config=opts;
            self=this;
            self.start('./',0);
            return this;
        },
        start: function (dir,deep) {
            let files=fs.readdirSync(dir);
            for(let file of files){
                //console.log(dir,file);
                self.print(file,deep);
                if(config.ignore.find(ignore=>{
                        let ignorePath=path.join(__dirname,ignore),filePath=path.join(__dirname,dir,file);
                        return ignorePath==filePath;
                    }))continue;
                if(self.isDir(path.join(dir,file))){
                    self.start(path.join(dir,file),deep+1);
                }
            }
        },
        print: function (file,deep) {
            console.log(self.line(deep)+file);
        },
        line: function (deep=0) {
            return new Array(deep+1).join(space)+line;
        },
        isDir: function (file) {
            return fs.statSync(file).isDirectory();
        }
    }
})().init({
    ignore:['/.git','/D_1/D_1-2/D_1-2-1']
});